# coding:utf-8
'''
Created on 2010-1-22

@author: Jason Green
@author-email: guileen@gmail.com
'''
from django.core.exceptions import ImproperlyConfigured
from django.utils.importlib import import_module

def import_any(name):
    try:
        return import_module(name)
    except:
        i = name.rfind('.')
        module, attr = name[:i], name[i + 1:]
        try:
            mod = import_module(module)
        except ImportError, e:
            raise ImproperlyConfigured('Error importing upload handler module %s: "%s"' % (module, e))
        except ValueError, e:
            raise ImproperlyConfigured('Error importing upload handler module. Is FILE_UPLOAD_HANDLERS a correctly defined list or tuple?')
        try:
            return getattr(mod, attr)
        except AttributeError:
            raise ImproperlyConfigured('Module "%s" does not define a "%s" upload handler backend' % (module, attr))
